using MediatR;
using Microsoft.AspNetCore.Mvc;
using RBAC.Domain.Dto.Output;
using RBAC.ErrorCode;
using RBAC.Read.Api.Application.Command.ERP.MaterialFile;
using RBAC.Read.Api.Application.Command.ERP.MaterialFile.Department;

namespace RBAC.Read.Api.Controllers.ERP
{
    /// <summary>
    /// 物料档案控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterialFileController : ControllerBase
    {
        private readonly IMediator mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">消息中介</param>
        public MaterialFileController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <param name="request">查询参数</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>分页部门数据</returns>
        [HttpGet]
        public Task<APIPaging<GetDepartmentListDto>> GetDepartmentList([FromQuery] GetDepartmentListCommand request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 获取物料分类树状图列表
        /// </summary>
        /// <param name="request">查询参数</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>物料分类树状列表数据</returns>
        [HttpGet]
        public Task<APIResult<List<GetMaterTypeListDto>>> GetMaterTypeList([FromQuery] GetMaterTypeListCommand request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 获取物料分页列表
        /// </summary>
        /// <param name="request">查询参数</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>分页物料数据</returns>
        [HttpGet]
        public Task<APIResult<APIPaging<GetMaterialListDto>>> GetMaterialPageList([FromQuery] GetMaterialPageCommand request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }
    }
}
